<?php
/*
 * Created on 2007-11-18
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
require_once(dirname(__FILE__)."/../common/constants.php");
require_once(DB_SESSION_DIR_PATH."/db_operator.php");

/*
 * Match status
 * 0 = created and waiting for the rival
 * 1 = rival received
 * 2 = rival accepted
 * 3 = match completed
 */
class MatchStatus {	
	const MATCH_CREATED		= 0;
	const MATCH_RECEIVED 	= 1;
	const MATCH_ACCEPTED 	= 2;
	const MATCH_COMPLETED 	= 3;
}
/*
 * Match property
 * 0 = public match. waiting for any team to play with.
 * 1 = private match. When the match request is sent to a team directly, the property is set to 1.
 * 2 = Match of one tournament.
 */
class MatchProperty {
	const MATCH_PUBLIC		= 0;
	const MATCH_PRIVATE		= 1;
	const MATCH_TOURNAMENT	= 2;
}
/*
 * 
 */
class SqlConstants {
	const ASTERISK = "*";
}
/*
 * @$input_array: should be a key-value pair. Key: column name; Value: column value to be filled.
 * Returned value: an array containing the columns missing.
 */
function validate_mandatory_columns($input_array, $mandatory_cols) 
{	
	$ret = array();
	
	$keys = array_keys($input_array);
	
	foreach ($mandatory_cols as $col) {
		
		if(!in_array($col, $keys, TRUE)) {
			$ret[] = $col;
		}
	}
	return $ret;
}

class DbTools {
	public static function delete_all() {
		$op = new DatabaseOperator();
		
		$conf_dir_path = dirname(__FILE__)."/../configuration/";
		
		// 1. member invite request table
		$op->config($conf_dir_path."member_invite_request_table.xml");
		$op->delete();
		
		// 2. match direct request table
		$op->config($conf_dir_path."match_direct_request_table.xml");
		$op->delete();
		
		// 3. match request table
		$op->config($conf_dir_path."match_request_table.xml");
		$op->delete();
		
		// 4. match result table
		$op->config($conf_dir_path."match_result_table.xml");
		$op->delete();
		
		// 5. match table
		$op->config($conf_dir_path."match_table.xml");
		$op->delete();
		
		// 6. team member table
		$op->config($conf_dir_path."team_member_table.xml");
		$op->delete();
		
		// 7. team table
		$op->config($conf_dir_path."team_table.xml");
		$op->delete();
		
		// 8. user table
		$op->config($conf_dir_path."user_table.xml");
		$op->delete();
	}
	
	public static function check_count_result($ret_array, $expected_count = 0) {
		if (count($ret_array) != 1)
			return FALSE;
		
		$row = $ret_array[0];
		
		if ($row["count(*)"] != $expected_count)
			return FALSE;
		
		return TRUE;
	}
}
?>
